<?php
require_once 'ini.php';

if($_POST['act'] && $_POST['act']=='login')
{
    $email = trim($_POST['email']);
    $password = trim($_POST['password']);
    $password = md5($password);
    $map =["and"=>["email"=>$email,"password"=>$password]];
    $ret = $register->get('db')->get("user","*",$map);
    if(!$ret)
    {
        $data['code'] = '0';
        echo json_encode($data);
        exit;
    }
    $_SESSION['admin'] = $ret;
    if($ret['user_group_id'] ==1)
    {
        $_SESSION['admin']['is_admin'] = 1;
    }
    $data['code'] = '1';
    echo json_encode($data);
    exit;
    // header("Location: index.php?");
}
else if($_GET['act'] && $_GET['act']=='logout')
{
    $_SESSION['admin']  =null;
    // $register->get("view")->display('login.twig');
    require_once 'build/login.html';
}

else{
    if(!$_SESSION['admin']['uid'])
    {
        // $register->get("view")->display('login.twig');
        require_once 'build/login.html';
    }
    else{
        $data =  $_SESSION;

        if(!$_SESSION['admin']['is_admin'])
        {
            $map['aid'] = $_SESSION['admin']['uid'];
        }

//        //查询订单和产品
//        $allOrderNum = $register->get("db")->count('order',$map);
//        $data['allOrderNum'] = $allOrderNum;
//
//        $product =   $register->get("db")->count('product',$map);
//        $data['product'] =   $product;
//
//        $map['add_time[<>]'] =[date("Y-m-d 00:00:00"),date("Y-m-d H:i:s")];
//
//        $dayOrderNum =    $register->get("db")->count('order',$map);
//        $data['dayOrderNum'] = $dayOrderNum;
//
//        $dayProduct =   $register->get("db")->count('product',$map);
//        $data['dayProductNum'] = $dayProduct;
//
//        $map['erp_status'] = ['FAIL','CREATE_FAIL'];
//        unset($map['add_time[<>]']);
//        $failNum   =     $register->get("db")->count('order',$map);
//        $data['failNum'] = $failNum;
//        // $register->get("view")->display('index.twig',$data);
        require_once 'build/index.html';
    }


}

